<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">
    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">

    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">
    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">
    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">
    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">
    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />
    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">
    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet"></head>
    <!--layui css-->
    <link href="<!--{eval echo register_static('layui/css/layui.css');}-->" rel="stylesheet"></head>

<body>

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->

<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->

    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid user-list">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">小程序管理</h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-4 col-sm-4 col-xs-4">
                                <div class="form-inline" role="form">
                                    <div class="form-group m-l-10">
                                    <button type="button" id="addbtn"  class="btn btn-success m-l-10">新增小程序</button>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div class="form-inline" role="form">
                                    <div class="form-group m-l-10">
                                        <div id="pages"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <br/>
                        <div>
                            <form class="layui-form" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">系统:</label>
                                    <div class="layui-input-inline">
                                        <select name="os" lay-filter="os" id="platform">
                                            <option value="ios">ios</option>
                                            <option value="android">android</option>
                                        </select>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <br/>
                        <div class="row" id="tbody_list">
                            <table class="layui-table" lay-even="" lay-skin="row">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>applet ID</th>
                                    <th>UID</th>
                                    <th>用户等级</th>
                                    <th>applet等级</th>
                                    <th>applet名字</th>
                                    <th>封面图</th>
                                    <th>状态</th>
                                    <th>管理状态</th>
                                    <th>包链接</th>
                                    <th>系统</th>
                                    <th>applet版本</th>
                                    <th>最大版本</th>
                                    <th>最小版本</th>
                                    <th>创建时间</th>
                                    <th>更新时间</th>
                                    <th width="150">操 作</th>
                                </tr>
                                </thead>
                                <tbody id="tbody">

                                </tbody>
                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div>

    </div>
    </div>
    </section>
    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->
<!-- Main Content Ends -->

<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>

<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<!--layui-->
<script src="<!--{eval echo register_static('layui/layui.js');}-->"></script>

<script id="appletTpl" type="text/html">
    <form class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">ID</label>
            <div class="layui-input-block">
                <input type="text" name="id" value="{{d.id}}" placeholder="ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序ID</label>
            <div class="layui-input-block">
                <input type="text" name="aid" value="{{d.aid}}" placeholder="AID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">UID</label>
            <div class="layui-input-block">
                <input type="text" name="uid" value="{{d.uid}}" placeholder="UID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户等级</label>
            <div class="layui-input-block">
                <input type="text" name="uid_level" value="{{d.uid_level}}" placeholder="用户等级" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序等级</label>
            <div class="layui-input-block">
                <input type="text" name="applet_level" value="{{d.applet_level}}" placeholder="小程序等级" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序名字</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="{{d.name}}" placeholder="小程序名字" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图</label>
            <div class="layui-input-block">
                <input type="text" name="cover" value="{{d.cover}}" placeholder="封面图" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="下线" {{d.status==1 ? 'checked' :''}}>
                <input type="radio" name="status" value="0" title="上线" {{d.status==0 ? 'checked' :''}}>
                <input type="radio" name="status" value="2" title="隐藏" {{d.status==2 ? 'checked' :''}}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理状态</label>
            <div class="layui-input-block">
                <input type="radio" name="admin" value="0" title="正常" {{d.admin==0 ? 'checked' :''}}>
                <input type="radio" name="admin" value="1" title="下线" {{d.admin==1 ? 'checked' :''}} >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">包链接</label>
            <div class="layui-input-block">
                <input type="text" name="zip_url" value="{{d.zip_url}}" placeholder="包链接" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">系统</label>
            <div class="layui-input-block">
                <input type="radio" name="platform" value="ios" title="ios"         {{d.platform =='ios' ? 'checked' :''}}>
                <input type="radio" name="platform" value="android" title="android" {{d.platform =='android' ? 'checked' :''}} >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序版本</label>
            <div class="layui-input-block">
                <input type="text" name="version" value="{{d.version}}" placeholder="小程序版本" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">最大版本</label>
            <div class="layui-input-block">
                <input type="text" name="max_version" value="{{d.max_version}}" placeholder="最大版本" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">最小版本</label>
            <div class="layui-input-block">
                <input type="text" name="min_version" value="{{d.min_version}}" placeholder="最小版本" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="action" value="{{d.action}}">
                <button class="layui-btn" lay-submit lay-filter="appletsData">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="lists">
    {{# layui.each(d, function(index, item){ }}
    <tr>
    <td>{{item.id}}</td>
    <td>{{item.aid}}</td>
    <td>{{item.uid}}</td>
    <td>{{item.uid_level}}</td>
    <td>{{item.applet_level}}</td>
    <td>{{item.name}}</td>
    <td><img src="{{item.cover}}" style="width: 100px;height: 100px;" alt=""></td>
    <td>
    {{# if(item.status==0) { }}
        上线
    {{# } }}
    {{# if(item.status==1) { }}
        下线
    {{# } }}
    {{# if(item.status==2) { }}
        隐藏
    {{# } }}
    </td>
    <td>
    {{# if(item.admin == 0) { }}
      正常
    {{# } }}
    {{# if(item.admin == 1) { }}
     下线
    {{# } }}
    </td>
    <td>{{item.zip_url}}</td>
    <td>{{item.platform}}</td>
    <td>{{item.version}}</td>
    <td>{{item.max_version}}</td>
    <td>{{item.min_version}}</td>
    <td>{{item.created_at}}</td>
    <td>{{item.updated_at}}</td>
    <td>
    <button class="layui-btn layui-btn-small layui-btn-normal editbtn" data-id="{{item.id}}">编辑</button>
        <button class="layui-btn layui-btn-small layui-btn-danger delbtn" data-id="{{item.id}}">删除</button>
        </td>
    </tr>
    {{# });}}
</script>
<script>
    layui.use(['jquery','layer','laytpl','form','laypage'],function () {
        var laytpl = layui.laytpl;
        var form   = layui.form();
        var $ = layui.jquery;
        var layer = layui.layer;
        var laypage = layui.laypage;
        var addDefaultData  = {
            id:1,aid:1,uid:7202207,uid_level:1,applet_level:1,name:'',cover:'',status:1,admin:0,zip_url:'',
            platform:'ios',version:'1',max_version:'',min_version:''
        };
        var start = 0;
        var length = 20;
        var os = 'ios';
        //分页
        laypage({
            cont: document.getElementById('pages'), //容器。值支持id名、原生dom对象，jquery对象,
            pages: 800, //总页数
            skin: 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
            groups: 8, //连续显示分页数
            jump:function(obj){
                var page = obj.curr;
                start = (page-1)*length;
                list(start,length);
            }
        });
        //列表
        function list(s,l) {
            $.ajax({
                type:'get',
                data:{os:os,start:s,length:l,do:'applets',op:'start',action:'getAppletList'},
                url:'admin.php?ac=admin',
                success:function (data) {
                    var html = laytpl($('#lists').html()).render(data.result);
                    $('#tbody').html(html);
                }
            })
        }
        function appletTpl(data,type) {
            var tpl = $('#appletTpl').html();
            data.action = type;
            var html= laytpl(tpl).render(data);
            layer.open({
                type:1,
                title:'新增小程序',
                content:html,
                area:['90%','80%'],
            });
            form.render();
        }

        //结果展示
        function resultStatus(data,y,n) {
            layer.closeAll();
            if(data){
                layer.msg(y)
            }else{
                layer.msg(n)
            }
            list(start,length)
        }
        //点击编辑
        $(document).on('click','.editbtn',function () {
            var id = $(this).data('id');
            $.ajax({
                type:'get',
                data:{id:id,do:'applets',op:'start',action:'getAppletDetail'},
                url:'admin.php?ac=admin',
                success:function (data) {
                    console.log(data)
                    appletTpl(data.result,'editApplets');
                }
            })
        });
        //选择系统
        form.on('select(os)',function (data) {
            os = data.value;
            list(start,length);
        })
        //点击新增
        $('#addbtn').on('click',function () {
            appletTpl(addDefaultData,'addApplets');
        })
        //点击删除
        $(document).on('click', '.delbtn', function () {
            var id = $(this).data('id');
            $.ajax({
                type:'get',
                data:{id:id,do:'applets',op:'start',action:'delApplets'},
                url:'admin.php?ac=admin',
                success:function (data) {
                    resultStatus(data.result,'删除成功','删除失败');
                }
            })
        })

        //监听提交
        form.on('submit(appletsData)', function(data){
//              console.log(data);
//            layer.msg(JSON.stringify(data.field));
//            return false;
            if(data.field.action == 'addApplets'){
                var y   = '新增成功';
                var n   = '新增失败';
            }
            if(data.field.action == 'editApplets'){
                var y   = '更新成功';
                var n   = '更新失败';
            }
            data.field['do'] = 'applets';
            data.field['op'] = 'start';
            $.ajax({
                type:'get',
                data:data.field,
                url:'admin.php?ac=admin',
                success:function (data) {
                    resultStatus(data, y, n);
                }
            })
            return false;
        });
    });
</script>
</body>
</html>